//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.dao.wills;

import com.aidong.dao.wills.BaseDao;
import com.aidong.model.wills.ContractSign;
import com.aidong.model.wills.ContractSignConfirm;
import java.util.Date;
import org.springframework.stereotype.Repository;

@Repository
public class ContractSignDao extends BaseDao<ContractSign, Integer> {
	public ContractSignDao() {
	}

	public ContractSign getByContractCode(String contractCode, String contractType) {
		return (ContractSign)this.getByWhere("contractCode=:p1 and contractType=:p2", new Object[]{contractCode, contractType});
	}

	public ContractSign getBySaleId(int saleId, String contractType) {
		return (ContractSign)this.getByWhere("saleId=:p1 and contractType=:p2", new Object[]{Integer.valueOf(saleId), contractType});
	}

	public void updateStatus(int id, int status) {
		String sql = "update ContractSign set status=:p1 where autoId=:p2";
		this.updateBySql(sql, new Object[]{Integer.valueOf(status), Integer.valueOf(id)});
	}

	public void updateConfirm(ContractSign sign, String userCode) {
		String sql = "update ContractSign set status=:p1 where autoId=:p2";
		this.updateBySql(sql, new Object[]{Integer.valueOf(3), sign.getAutoId()});
		ContractSignConfirm signConfirm = new ContractSignConfirm();
		signConfirm.setAutoId(sign.getAutoId());
		signConfirm.setShopCode(sign.getShopCode());
		signConfirm.setContractCode(sign.getContractCode());
		signConfirm.setContractType(sign.getContractType());
		signConfirm.setSaleId(sign.getSaleId());
		signConfirm.setMemberCode(sign.getMemberCode());
		signConfirm.setMemberName(sign.getMemberName());
		signConfirm.setImageHead(sign.getImageHead());
		signConfirm.setImageSign(sign.getImageSign());
		signConfirm.setPrintLabel(Integer.valueOf(0));
		signConfirm.setCreateUser(userCode);
		signConfirm.setCreateTime(new Date());
		signConfirm.setUpdateTime(new Date());
		this.getSession().save(signConfirm);
		if("01".equals(signConfirm.getContractType())) {
			sql = "update MemberContract set signStatus=1, reviewSubmitDate=getdate() where saleId=:p1";
		} else if("02".equals(signConfirm.getContractType())) {
			sql = "update PtContract set signStatus=1, reviewSubmitDate=getdate() where saleId=:p1";
		} else if("03".equals(signConfirm.getContractType())) {
			sql = "update MemberEarnest set signStatus=1 where saleId=:p1";
		} else if("04".equals(signConfirm.getContractType())) {
			sql = "update MemberStopedCard set signStatus=1 where saleId=:p1";
		} else if("05".equals(signConfirm.getContractType())) {
			sql = "update MemberTransfer set signStatus=1 where saleId=:p1";
		} else if("06".equals(signConfirm.getContractType())) {
			sql = "update MemberChangeShop set signStatus=1 where saleId=:p1";
		} else if("07".equals(signConfirm.getContractType())) {
			sql = "update MemberChangeCard set signStatus=1 where saleId=:p1";
		} else if("08".equals(signConfirm.getContractType())) {
			sql = "update BoxRent set signStatus=1 where saleId=:p1";
		} else if("09".equals(signConfirm.getContractType())) {
			sql = "update KyContract set signStatus=1 where saleId=:p1";
		} else {
			if(!"10".equals(signConfirm.getContractType())) {
				return;
			}

			sql = "update PtBespeak set status=3 where autoId=:p1 and status=2";
		}

		this.updateBySql(sql, new Object[]{signConfirm.getSaleId()});
	}
}
